﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Two-Columns-Left.master" AutoEventWireup="true"
    CodeBehind="Sach.aspx.cs" Inherits="BookStore.SachPage" %>

<asp:Content ID="Content4" ContentPlaceHolderID="HeadContent" runat="server">
    <title>Books - Book Store</title>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="BreadcrumbsContent" runat="server">
    <div class="breadcrumbs">
        <ul>
            <li class="home"><a href="./Default.aspx" title="Go to Home Page">Sách</a> <span>&#187;</span>
            </li>
            <li class="category3"><strong>Tiểu Thuyết</strong> </li>
        </ul>
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainColumnContent" runat="server">
    <div class="page-title category-title">
        <h1>
            <asp:Label ID="PageTitle" runat="server" Text="Title"></asp:Label>
        </h1>
    </div>
    <div class="category-products">
        <div class="toolbar">
            <!--div class="pager">
            </div>
            <div class="sorter">
                <div class="sort-by">
                    <label>
                        Sort by</label>
                    <select>
                        <option value="position" selected="selected">Ngày phát hành</option>
                        <option value="name">Tên </option>
                        <option value="price">Giá </option>
                    </select>
                    <a href="#" title="Set Descending Direction">
                        <img src="./images/i_asc_arrow.gif" alt="Set Descending Direction" class="v-middle" /></a>
                </div>
                <div class="limiter">
                    <label>
                        Show</label>
                    <select>
                        <option value="9" selected="selected">9 </option>
                        <option value="15">15 </option>
                        <option value="30">30 </option>
                    </select>
                </div>
            </div-->
        </div>
        <asp:DataList ID="ProductsGrid" ItemStyle-CssClass="item" 
            CssClass="products-grid" runat="server" DataKeyField="MaSach"
            DataSourceID="TatCaSachDS" RepeatColumns="2" RepeatDirection="Horizontal" 
            onitemcommand="ProductsGrid_ItemCommand" >
            <ItemTemplate>
                <a href="./ChiTiet.aspx?bookid=<%# Eval("MaSach") %>" title="<%# Eval("TenSach") %>"
                    class="product-image">
                <asp:Image ID="img_product" runat="server" Width="132" Height="200" ImageUrl='<%# Eval("ImageURL") %>' ToolTip='<%# Eval("TenSach") %>' /></a>
                <div class="product-name">                   
                    <asp:Label ID="lbl_ten" runat="server" Text='<%# Eval("TenSach") %>'></asp:Label>
                </div>
                <div class="product-description">
                    <asp:Label ID="bookdescription" runat="server" Text='<%# Eval("sMoTa") %>'></asp:Label>...
                </div>
                <div class="price-box">
                    <span class="regular-price" id="Span6"><span class="price">
                        <asp:Label ID="lbl_giahienthi" runat="server" Text='<%# Eval("Gia") %>'></asp:Label>
                        <asp:HiddenField ID="lbl_gia" runat="server" Value='<%# Eval("DonGia") %>' />
                    </span></span>
                </div>
               <div class="add-to-cart">
                    <asp:LinkButton CssClass="btAddToCart" ID="LinkButton1" CommandName="datmua" CommandArgument='<%# Eval("MaSach") %>' runat="server">
                        Add to Cart</asp:LinkButton>
                </div>
                <asp:HiddenField ID="txtKluong" runat="server" Value='<%# Eval("KhoiLuong") %>' />
                <asp:HiddenField ID="txtBDay" runat="server" Value='<%# Eval("BeDay") %>' />
                <asp:HiddenField ID="txtCCao" runat="server" Value='<%# Eval("ChieuCao") %>' />
                <asp:HiddenField ID="txtCRong" runat="server" Value='<%# Eval("ChieuRong") %>' />
            </ItemTemplate>
        </asp:DataList>
        <div class="pagging">
            <asp:Label CssClass="pageStatus" ID="CurrentPage" runat="server" Text="0"></asp:Label>
            <asp:Button CssClass="paggingButton" ID="PrevPage" runat="server" Text="Previous" />
            <asp:Button  CssClass="paggingButton" ID="NextPage" runat="server" Text="Next" />
        </div>


        <asp:SqlDataSource ID="DSachSachDS" runat="server" ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>"
            SelectCommand="SELECT *
FROM (SELECT ROW_NUMBER() OVER (ORDER BY [TenSach]) as [row], *, LEFT([Mota], 120) as [sMoTa], LEFT(convert(varchar, cast([DonGia] as money), 1), LEN(convert(varchar, cast([DonGia] as money), 1)) - 3)  as [Gia] FROM [Sach] WHERE (([MaNXB] = @MaNXB) OR ([MaLoaiSach] = @MaLoaiSach))) as rs
WHERE row &gt; (@page - 1) * 8 and row &lt;= @page * 8 ">
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="0" Name="MaNXB" QueryStringField="nxb" Type="Int32" />
                <asp:QueryStringParameter DefaultValue="0" Name="MaLoaiSach" QueryStringField="loaisach"
                    Type="Int32" />
                <asp:QueryStringParameter DefaultValue="1" Name="page" 
                    QueryStringField="page" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="TatCaSachDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
            SelectCommand="select * 
from (SELECT ROW_NUMBER() OVER (ORDER BY TenSach) as row, *, LEFT([Mota], 120) as [sMoTa], LEFT(convert(varchar, cast([DonGia] as money), 1), LEN(convert(varchar, cast([DonGia] as money), 1)) - 3)  as [Gia] FROM Sach) as rs
WHERE row &gt; (@page - 1) * 8 and row &lt;= @page * 8" >
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="1" Name="page" 
                    QueryStringField="page" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="SachMoiDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" SelectCommand="SELECT *
FROM (SELECT ROW_NUMBER() OVER (ORDER BY [NgayXuatBan]) as [row], *, LEFT([Mota], 120) as [sMoTa], LEFT(convert(varchar, cast([DonGia] as money), 1), LEN(convert(varchar, cast([DonGia] as money), 1)) - 3)  as [Gia]
FROM [Sach]
WHERE DATEDIFF(day, [NgayXuatBan], GETDATE()) &lt; 45) as rs
WHERE row &gt; (@page - 1) * 8 and row &lt;= @page * 8">
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="1" Name="page" QueryStringField="page" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="SachBanChayDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" SelectCommand="select * from (SELECT Row_number() over (ORDER BY ctHoaDon.SoLuong DESC, Sach.NgayXuatBan DESC) as row, [Sach].*, LEFT([Mota], 120) as [sMoTa], LEFT(convert(varchar, cast([DonGia] as money), 1), LEN(convert(varchar, cast([DonGia] as money), 1)) - 3)  as [Gia], ctHoaDon.[SoLuong] as [soluongban] FROM [Sach] LEFT JOIN (select MaSach,sum(SoLuong) as soluong  from ChiTietHoaDon left join HoaDOn ON HoaDon.maHD=ChiTietHoaDon.maHD	where   (MONTH(HoaDon.NgayThang) = MONTH(DATEADD(month, - 1, GETDATE()))) OR (MONTH(HoaDon.NgayThang) = MONTH(GETDATE())) group by (MaSach)) as ctHoaDon  on Sach.MaSach=ctHoaDon.MaSach Where Sach.SoLuong &gt; 0 ) as rs
where row &gt; (@page - 1)*8 and row &lt;= @page * 8 and soluongban &gt; 0">
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="1" Name="page" 
                    QueryStringField="page" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="TimKiemDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
            SelectCommand="SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY [TenSach]) as [row], *, LEFT([Mota], 120) as [sMoTa], LEFT(convert(varchar, cast([DonGia] as money), 1), LEN(convert(varchar, cast([DonGia] as money), 1)) - 3)  as [Gia] FROM [Sach] WHERE ([TenSach] LIKE '%' + @TenSach + '%')) as rs
WHERE row &gt; (@page - 1) * 8 and row &lt;= @page * 8">
            <SelectParameters>
                <asp:QueryStringParameter Name="TenSach" QueryStringField="key" 
                    Type="String" DefaultValue="" />
                <asp:QueryStringParameter DefaultValue="1" Name="page" 
                    QueryStringField="page" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="LeftColumnContent" runat="server">
    <div class="block block-layered-nav">
        <div class="block-title">
            <strong><span>Tìm theo</span></strong>
        </div>
        <div class="block-content">
            <p class="block-subtitle">
                Danh mục
            </p>
            <dl id="narrow-by-list">
                <dt>
                    <asp:HyperLink NavigateUrl="~/Sach.aspx" ID="leftPanel_AllBookLink" runat="server">Tất cả</asp:HyperLink>
                    <asp:Label CssClass="currentCategory" ID="leftPanel_AllBookLabel" runat="server"
                        Text="Tất cả"></asp:Label></dt>
                <dt>
                    <asp:HyperLink NavigateUrl="~/Sach.aspx?sachbanchay=1" ID="leftPanel_BestSellerLink"
                        runat="server">Bán chạy nhất</asp:HyperLink>
                    <asp:Label CssClass="currentCategory" ID="leftPanel_BestSellerLabel" runat="server"
                        Text="Bán chạy nhất"></asp:Label></dt>
                <dt>
                    <asp:HyperLink NavigateUrl="~/Sach.aspx?sachmoi=1" ID="leftPanel_NewBookLink"
                        runat="server">Sách mới</asp:HyperLink>
                    <asp:Label CssClass="currentCategory" ID="leftPanel_NewBookLabel" runat="server"
                        Text="Sách mới"></asp:Label>
                </dt>
                <dt>Loại sách </dt>
                <dd>
                    <ol>
                        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="LoaiSachDS">
                            <ItemTemplate>
                                <li>
                                    <asp:HyperLink Visible='<%# Eval("MaLoaiSach").ToString() != Page.Request.QueryString["loaisach"] %>'
                                        NavigateUrl='<%# "./Sach.aspx?loaisach=" + Eval("MaLoaiSach") %>' ID="leftPanel_LoaiSachLink"
                                        runat="server" Text='<%# Eval("TenLoaiSach") %>'></asp:HyperLink>
                                    <asp:Label CssClass="currentCategory" Visible='<%# Eval("MaLoaiSach").ToString() == Page.Request.QueryString["loaisach"] %>'
                                        ID="leftPanel_LoaiSachLabel" runat="server" Text='<%# Eval("TenLoaiSach") %>'></asp:Label>
                                    &nbsp;(<%# Eval("SoSach") %>)</li>
                            </ItemTemplate>
                        </asp:Repeater>
                        <asp:SqlDataSource ID="LoaiSachDS" runat="server" ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>"
                            SelectCommand="SELECT LoaiSach.MaLoaiSach, LoaiSach.TenLoaiSach, COUNT(Sach.MaSach) AS SoSach FROM LoaiSach LEFT JOIN Sach ON LoaiSach.MaLoaiSach = Sach.MaLoaiSach GROUP BY LoaiSach.MaLoaiSach, LoaiSach.TenLoaiSach">
                        </asp:SqlDataSource>
                    </ol>
                </dd>
                <dt>Nhà xuất bản </dt>
                <dd>
                    <ol>
                        <asp:Repeater ID="Repeater2" runat="server" DataSourceID="NhaXuatBanDS">
                            <ItemTemplate>
                                <li>
                                    <asp:HyperLink Visible='<%# Eval("MaNXB").ToString() != Page.Request.QueryString["nxb"] %>'
                                        ID="leftPanel_NXBLink" NavigateUrl='<%# "~/Sach.aspx?nxb=" + Eval("MaNXB") %>'
                                        runat="server"><%# Eval("TenNXB") %></asp:HyperLink>
                                    <asp:Label Visible='<%# Eval("MaNXB").ToString() == Page.Request.QueryString["nxb"] %>'
                                        CssClass="currentCategory" ID="leftPanel_NXBLabel" runat="server" Text='<%#Eval("TenNXB") %>'></asp:Label>
                                    &nbsp;(<%# Eval("SoSach") %>) </li>
                            </ItemTemplate>
                        </asp:Repeater>
                        <asp:SqlDataSource ID="NhaXuatBanDS" runat="server" ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>"
                            SelectCommand="SELECT NhaXuatBan.MaNXB, NhaXuatBan.TenNXB, COUNT(Sach.MaSach) AS SoSach FROM NhaXuatBan LEFT OUTER JOIN Sach ON NhaXuatBan.MaNXB = Sach.MaNXB GROUP BY NhaXuatBan.MaNXB, NhaXuatBan.TenNXB">
                        </asp:SqlDataSource>
                    </ol>
                </dd>
            </dl>
        </div>
    </div>
</asp:Content>
